﻿@{
	ViewBag.Title = "My Comet Sample";
	<script src="/Scripts/HashMap.js"  type="text/javascript"></script>
	<script src="/Scripts/FlyComet.js"  type="text/javascript"></script>
}

<h2>@ViewBag.Message</h2>
<p>
    Asp .net MVC 3 sample to show how to use FlyComet for Live Updates/Server Push.
    Visit <a href="http://www.codersource.net">Codersource.net</a> for more info.
</p>
<div>
Channel ID: <input type="text" id="txtchannel" value="testchannel" /> <br /><br />
<input type="button" id="cmdSubscribe" value="Subscribe" /> &nbsp;&nbsp;&nbsp;
<input type="button" id="cmdUnsubscribe" value="UnSubscribe" />
</div>
<h3>Received Data:</h3>
<div id="receiveddata"></div>

<script type="text/javascript">
    var flyComet = null;
    var onMessageReceived = function (type, data) {
        var text = $("#receiveddata").html() + "<br />" + "Received type:" + type + ", data :" + data;
        $("#receiveddata").html(text);
    }

    cmdSubscribe.onclick = function () {
        var channelid = $("#txtchannel").val();
        flyComet.SubscribeToChannel(channelid, false);
    }

    cmdUnsubscribe.onclick = function ()
    {
        var channelid = $("#txtchannel").val();
        flyComet.RemoveSubscription(channelid);
    }

    $(function () {
        flyComet = $.FlyComet(onMessageReceived);
        flyComet.Connect();
    });
</script>
